package com.mt.component.context;

import java.util.Properties;

import org.apache.log4j.Logger;


/**
 * 类名称：ContextFactory <br>
 * 类描述： <br>
 * 创建人： 马腾 <br>
 * 创建时间：Dec 1, 2012 3:38:43 PM <br>
 * 修改人： 马腾 <br>
 * 修改时间：Dec 1, 2012 3:38:43 PM <br>
 */
public class ContextFactory {
	
	private static Logger logger = Logger.getLogger(ContextFactory.class);
	
	private Context context;
	
	private static ContextFactory instance = null;
	
	public static synchronized ContextFactory getInstance(){
		if(instance == null){
			instance = new ContextFactory();
		}
		return instance;
	}

	private ContextFactory(){
		context = new ContextImpl();
	}
	
	public String getMessage(String key){
		return context.getMessage(key);
	}
	
	public void initMessages(Properties properties){ 
		logger.info("load message properties");
		for (Object key : properties.keySet()) {
			context.setMessage((String) key, (String) properties.get(key));
			logger.info(key + "=" + properties.get(key));
		}
	} 
	
	public String getConfig(String key){
		return context.getConfig(key);
	}

	public void initConfigs(Properties properties){ 
		logger.info("load confirg properties");
		for (Object key : properties.keySet()) {
			context.setConfig((String) key, (String) properties.get(key));
			logger.info(key + "=" + properties.get(key));
		}
	}
}
